package com.nwpu.coursesupport.service.imple;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.nwpu.coursesupport.criteria.ResourceSearchCriteria;
import com.nwpu.coursesupport.entity.Resource;
import com.nwpu.coursesupport.enumeration.FileType;
import com.nwpu.coursesupport.enumeration.Gender;
import com.nwpu.coursesupport.mapper.ResourceMapper;
import com.nwpu.coursesupport.service.AbstractService;
import com.nwpu.coursesupport.tool.RandomUtil;

public class UserService extends AbstractService{

	@Autowired
    private ResourceMapper resourceMapper;
	
	protected String getHeaderImage(Gender gender){
    	ResourceSearchCriteria sc=new ResourceSearchCriteria();
    	if(gender==Gender.MALE){
    		sc.setType(FileType.MALE);
    	}else{
    		sc.setType(FileType.FEMAIL);
    	}
		
		List<Resource> resources=this.resourceMapper.find(sc);
		if(resources==null||resources.size()<=0){
			return null;
		}else if(resources.size()==1){
			return resources.get(0).getFileKey();
		}else{
			return resources.get(RandomUtil.random.nextInt(resources.size()-1)).getFileKey();
		}
    }
}
